package lesson03;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpServerDemo02 {
    public static void main(String[] args) throws Exception {
        //开放段
        //等待客户端的连接
        DatagramSocket socket = new DatagramSocket(9090);
        //接收数据包
        byte[] buffer = new byte[1024]; //接收临时区域
        DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);

        //阻塞接收
        socket.receive(packet);

        System.out.println(packet.getAddress().getHostAddress());
        System.out.println(new String(packet.getData(),0,packet.getLength()));

        //关闭流
        socket.close();

    }
}
